#-*- coding:UTF-8 -*-
'''
Created on 2012-7-19
生产者-消费者模型
@author: Administrator
'''

from Queue import Queue
from time import ctime
from random import randint
from using_threading import MyThread

#创建大小为32的队列
q = Queue(32)

def writeQ(param):
    q.put(param, False)
    print '队列元素数量:%s' % q.qsize()

def readQ(param):
    val = q.get(True)
    print '元素:', val

funcs = [writeQ, readQ]

def main():
    threads = []
    for i in range(1, 10):
        if i % 2 == 0:
            t = MyThread(funcs[1], (i,), funcs[1].__name__) 
        else:
            t = MyThread(funcs[0], (i,), funcs[0].__name__) 
        t.start()
        threads.append(t)
    
    for threadMy in threads:
        threadMy.join()
        
    print '执行完毕'

if __name__ == '__main__': 
    main()
